import Vue from 'vue'
import Router from 'vue-router'
/* Layout */
import Layout from '@/layout'
// import customerCenter from './customerCenter'
// import orderCenter from './orderCenter'
// import workOrderCenter from './workOrderCenter'
// import callCenter from './callCenter'
// import distributionManage from './distributionManage'
import goodsCenter from './goodsCenter'
// import stockManage from './stockManage'
// import cylinderManage from './cylinderManage'
import safetySupervise from './safetySupervise'
import inventory from './inventory'
import financialManage from './financialManage'
import systemSetting from './systemSetting'
// import other from './other'
import customerManage from './customerManage'
import salesService from './salesService'
import orderManage from './orderManage'
import distributionManage from './distributionManage'

Vue.use(Router)

/**
 * hidden: true                  当设置 true 的时候该路由不会在菜单中出现 如401，login等页面，或者如一些编辑页面/edit/1  (默认 false)
 * name:'router-name'            设定路由的名字，一定要填写不然使用<keep-alive>时会出现页面操作无法记录的问题
 *                               如果name是 foo.xxx 那么该路由将会作为 name 是 foo 的路由的下一级页面，并自动提供提供前进加载后退缓存功能
 * meta : {
    title: 'title'               设置该路由在菜单和面包屑中展示的名字
    icon: 'svg-name'             设置该路由的菜单图标
    affix: true                  如果设置为true该路由对应的标签将一直显示在标签页中
    breadcrumb: false            如果设置为false该路由将不会显示在面包屑中（默认true）
    activeMenu: '/foo'           如果设置对应路由地址,访问本路由时菜单栏会高亮你设置路由对应的菜单
    activeTag: '/foo'			       如果设置对应路由地址,访问本路由时标签页会高亮你设置路由对应的标签
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/',
    redirect: '/home/index',
    constant: true
  },
  {
    path: '/demo',
    hidden: true,
    constant: true,
    component: Layout,
    name: 'demo',
    meta: { title: '示范页', icon: 'logo', affix: true },
    redirect: 'demo/table',
    children: [
      {
        path: 'table',
        name: 'table',
        component: () => import('@/views/demo/index'),
        meta: { title: '表格' }
      },
      {
        path: 'export-excel',
        name: 'exportExcel',
        component: () => import('@/views/demo/exportExcel'),
        meta: { title: '纯前端导出excel' }
      },
      {
        path: 'report',
        name: 'report',
        component: () => import('@/views/demo/report'),
        meta: { title: '报表' }
      },
      {
        path: 'addition',
        name: 'addition',
        component: () => import('@/views/demo/addition'),
        meta: { title: '商品分类' }
      }
    ]
  },
  {
    path: '/home',
    constant: true,
    component: Layout,
    children: [
      {
        path: 'index',
        constant: true,
        name: '首页',
        component: () => import('@/views/home/index'),
        meta: { title: '首页', icon: 'menu-home', menuId: 1, showIndex: 1, affix: true }
      }
    ]
  },
  {
    path: '/print',
    hidden: true,
    name: '打印预览',
    component: () => import('@/views/print/index'),
    meta: { title: '打印预览' },
    target: true
  },
  {
    path: '/editPrint',
    hidden: true,
    name: '编辑模版',
    component: () => import('@/views/systemSetting/printConfig/components/editPrint'),
    meta: { title: '编辑模版' },
    target: true
  },
  {
    path: '/app/lpgtob/spectaculars/batchDispath',
    hidden: true,
    name: '待派单订单',
    component: () => import('@/views/spectaculars/batchDispath/index'),
    meta: { title: '待派单订单' },
    target: true
  },
  {
    path: '/app/lpgtob/spectaculars/depositManage',
    hidden: true,
    name: '待审核押金单',
    component: () => import('@/views/spectaculars/depositManage/index'),
    meta: { title: '待审核押金单' },
    target: true
  },
  {
    path: '/app/lpgtob/spectaculars/homeCode',
    hidden: true,
    name: '一户一码待处理',
    component: () => import('@/views/spectaculars/homeCode/index'),
    meta: { title: '一户一码待处理' },
    target: true
  },
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path*',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/components/phoneUpload', // PC端点手机扫码上传
    hidden: true,
    name: '附件上传',
    component: () => import('@/views/components/NormalReceiptsAdd/components/phoneUploadPage.vue'),
    target: true
  }
]

if (process.env.VUE_APP_USE_LOGIN !== 'false') {
  constantRoutes.push({
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  })
}

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
  {
    path: '',
    linkUrl: '',
    component: Layout,
    meta: { title: '报表统计', icon: 'menu-reportCenter', menuId: 8, showIndex: 10 }
  },
  ...inventory,
  ...safetySupervise,
  ...financialManage,
  ...goodsCenter,
  ...systemSetting,
  ...customerManage,
  ...salesService,
  ...orderManage,
  ...distributionManage,

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404' }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
